<template>
  <a-modal
    :title="title"
    :after-close="reset"
    @ok="submit"
  >
    <a-form
      ref="formRef"
      :model="form"
      :rules="rules"
      :label-col="{style: { width: '80px' }}"
    >
                                                        <a-form-item label="商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)" name="merId">
                    <a-input  v-model:value="form.merId" placeholder="商户Id(0为总后台管理员创建,不为0的时候是商户后台创建)"></a-input>
                </a-form-item>
                                                <a-form-item label="商品图片" name="image">
                    <a-input  v-model:value="form.image" placeholder="商品图片"></a-input>
                </a-form-item>
                                                <a-form-item label="轮播图" name="sliderImage">
                    <a-input  v-model:value="form.sliderImage" placeholder="轮播图"></a-input>
                </a-form-item>
                                                <a-form-item label="商品名称" name="storeName">
                    <a-input  v-model:value="form.storeName" placeholder="商品名称"></a-input>
                </a-form-item>
                                                <a-form-item label="商品简介" name="storeInfo">
                    <a-input  v-model:value="form.storeInfo" placeholder="商品简介"></a-input>
                </a-form-item>
                                                <a-form-item label="关键字" name="keyword">
                    <a-input  v-model:value="form.keyword" placeholder="关键字"></a-input>
                </a-form-item>
                                                <a-form-item label="商品条码（一维码）" name="barCode">
                    <a-input  v-model:value="form.barCode" placeholder="商品条码（一维码）"></a-input>
                </a-form-item>
                                                <a-form-item label="分类id" name="cateId">
                    <a-input  v-model:value="form.cateId" placeholder="分类id"></a-input>
                </a-form-item>
                                                <a-form-item label="商品价格" name="price">
                    <a-input  v-model:value="form.price" placeholder="商品价格"></a-input>
                </a-form-item>
                                                <a-form-item label="会员价格" name="vipPrice">
                    <a-input  v-model:value="form.vipPrice" placeholder="会员价格"></a-input>
                </a-form-item>
                                                <a-form-item label="市场价" name="otPrice">
                    <a-input  v-model:value="form.otPrice" placeholder="市场价"></a-input>
                </a-form-item>
                                                <a-form-item label="邮费" name="postage">
                    <a-input  v-model:value="form.postage" placeholder="邮费"></a-input>
                </a-form-item>
                                                <a-form-item label="单位名" name="unitName">
                    <a-input  v-model:value="form.unitName" placeholder="单位名"></a-input>
                </a-form-item>
                                                <a-form-item label="排序" name="sort">
                    <a-input  v-model:value="form.sort" placeholder="排序"></a-input>
                </a-form-item>
                                                <a-form-item label="销量" name="sales">
                    <a-input  v-model:value="form.sales" placeholder="销量"></a-input>
                </a-form-item>
                                                <a-form-item label="库存" name="stock">
                    <a-input  v-model:value="form.stock" placeholder="库存"></a-input>
                </a-form-item>
                                                <a-form-item label="状态（0：未上架，1：上架）" name="isShow">
                    <a-input  v-model:value="form.isShow" placeholder="状态（0：未上架，1：上架）"></a-input>
                </a-form-item>
                                                <a-form-item label="是否热卖" name="isHot">
                    <a-input  v-model:value="form.isHot" placeholder="是否热卖"></a-input>
                </a-form-item>
                                                <a-form-item label="是否优惠" name="isBenefit">
                    <a-input  v-model:value="form.isBenefit" placeholder="是否优惠"></a-input>
                </a-form-item>
                                                <a-form-item label="是否精品" name="isBest">
                    <a-input  v-model:value="form.isBest" placeholder="是否精品"></a-input>
                </a-form-item>
                                                <a-form-item label="是否新品" name="isNew">
                    <a-input  v-model:value="form.isNew" placeholder="是否新品"></a-input>
                </a-form-item>
                                                <a-form-item label="添加时间" name="addTime">
                    <a-input  v-model:value="form.addTime" placeholder="添加时间"></a-input>
                </a-form-item>
                                                <a-form-item label="是否包邮" name="isPostage">
                    <a-input  v-model:value="form.isPostage" placeholder="是否包邮"></a-input>
                </a-form-item>
                                                <a-form-item label="是否删除" name="isDel">
                    <a-input  v-model:value="form.isDel" placeholder="是否删除"></a-input>
                </a-form-item>
                                                <a-form-item label="商户是否代理 0不可代理1可代理" name="merUse">
                    <a-input  v-model:value="form.merUse" placeholder="商户是否代理 0不可代理1可代理"></a-input>
                </a-form-item>
                                                <a-form-item label="获得积分" name="giveIntegral">
                    <a-input  v-model:value="form.giveIntegral" placeholder="获得积分"></a-input>
                </a-form-item>
                                                <a-form-item label="成本价" name="cost">
                    <a-input  v-model:value="form.cost" placeholder="成本价"></a-input>
                </a-form-item>
                                                <a-form-item label="秒杀状态 0 未开启 1已开启" name="isSeckill">
                    <a-input  v-model:value="form.isSeckill" placeholder="秒杀状态 0 未开启 1已开启"></a-input>
                </a-form-item>
                                                <a-form-item label="砍价状态 0未开启 1开启" name="isBargain">
                    <a-input  v-model:value="form.isBargain" placeholder="砍价状态 0未开启 1开启"></a-input>
                </a-form-item>
                                                <a-form-item label="是否优品推荐" name="isGood">
                    <a-input  v-model:value="form.isGood" placeholder="是否优品推荐"></a-input>
                </a-form-item>
                                                <a-form-item label="是否单独分佣" name="isSub">
                    <a-input  v-model:value="form.isSub" placeholder="是否单独分佣"></a-input>
                </a-form-item>
                                                <a-form-item label="虚拟销量" name="ficti">
                    <a-input  v-model:value="form.ficti" placeholder="虚拟销量"></a-input>
                </a-form-item>
                                                <a-form-item label="浏览量" name="browse">
                    <a-input  v-model:value="form.browse" placeholder="浏览量"></a-input>
                </a-form-item>
                                                <a-form-item label="商品二维码地址(用户小程序海报)" name="codePath">
                    <a-input  v-model:value="form.codePath" placeholder="商品二维码地址(用户小程序海报)"></a-input>
                </a-form-item>
                                                <a-form-item label="淘宝京东1688类型" name="soureLink">
                    <a-input  v-model:value="form.soureLink" placeholder="淘宝京东1688类型"></a-input>
                </a-form-item>
                                                <a-form-item label="主图视频链接" name="videoLink">
                    <a-input  v-model:value="form.videoLink" placeholder="主图视频链接"></a-input>
                </a-form-item>
                                                <a-form-item label="运费模板ID" name="tempId">
                    <a-input  v-model:value="form.tempId" placeholder="运费模板ID"></a-input>
                </a-form-item>
                                                <a-form-item label="规格 0单 1多" name="specType">
                    <a-input  v-model:value="form.specType" placeholder="规格 0单 1多"></a-input>
                </a-form-item>
                                                <a-form-item label="活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团" name="activity">
                    <a-input  v-model:value="form.activity" placeholder="活动显示排序0=默认, 1=秒杀，2=砍价，3=拼团"></a-input>
                </a-form-item>
                                                <a-form-item label="展示图" name="flatPattern">
                    <a-input  v-model:value="form.flatPattern" placeholder="展示图"></a-input>
                </a-form-item>
                                                <a-form-item label="是否回收站" name="isRecycle">
                    <a-input  v-model:value="form.isRecycle" placeholder="是否回收站"></a-input>
                </a-form-item>
                        </a-form>
  </a-modal>
</template>

<script setup lang="ts">
import { storeproductAddup, storeproductinfo } from './api';
import { storeproduct, type Istoreproduct } from './entity';
import { validReg } from '@/utils/validate';

const props = withDefaults(defineProps<{
  data: Partial<Istoreproduct>
}>(),{
})
const title = computed(() => props.data.id ? '编辑' : '新增')
const { formRef, submit, close } = useDialog({ validCallback: save })

let form = $ref(new storeproduct())
watchEffect(() => {
  if (props.data.id) {
    storeproductinfo(props.data.id).then(res => {
      form.setProps(res)
    })
  }
})

const rules = {
        storeproductName: [validReg('required', '请输入用户名')]
}

onMounted(() => {
})
const emit = defineEmits(['change'])
function save() {
    storeproductAddup(form).then(() => {
    AntMessage.success('保存成功')
    close()
    emit('change')
  })
}

function reset() {
  form = new storeproduct()
}
</script>

<style lang="less"></style>